Repository navigation
fix: keep USING / WITH CHECK parentheses for scalar subquery policy expressions (#718) - #721
Merged
Merged
Conversation
…xpressions (#718) Co-Authored-By: Tianzhou <t@bytebase.com>
Contributor
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Contributor
[Medium impact] This PR appears safe to merge; no actionable issues were found. SummaryFixes policy SQL that mistakes a scalar subquery’s parentheses for the parentheses required by
Reviews (1) · Last reviewed commit: "fix: keep USING / WITH CHECK parentheses..." · Reviewed by Greptile |
…licy clauses Co-Authored-By: Tianzhou <t@bytebase.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #718.
ensureParentheses(policy.go) treated any expression that starts with(and ends with)as already wrapped.pg_get_exprrenders a scalar subquery as( SELECT ... ), soUSING ((SELECT is_allowed()))came out asUSING ( SELECT is_allowed() AS is_allowed), which PostgreSQL rejects. This brokeCREATE POLICYandALTER POLICYin dump/plan/apply.An expression now counts as wrapped only when:
(is closed by its last)(uses the existingmatchingParen, which skips string literals and quoted identifiers, so(a) OR (b)is no longer treated as wrapped), andSELECT,WITHorVALUES(keywordAtchecks word boundaries, so(with_flag)is still treated as wrapped).Tests
create_policy/add_policy: added CREATE POLICY cases with a scalar subquery in USING and in WITH CHECKcreate_policy/alter_policy_using: added an ALTER POLICY case where the USING scalar subquery changesTestEnsureParenthesesunit testLink to Devin session: https://app.devin.ai/sessions/314326a464fb4b3c9fbe6ccc32736cdf
Open in Devin Desktop: https://app.devin.ai/desktop/session/314326a464fb4b3c9fbe6ccc32736cdf?variant=devin
Requested by: @tianzhou
🟢 Devin Review found nothing to fix · View findings